package cn.likole.oj.service;

import cn.likole.oj.bean.Problem;
import cn.likole.oj.bean.User;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

/**
 * Created by likole on 7/28/18.
 */
@IocBean
public class ProblemService {

    @Inject
    private Dao dao;

    /**
     * 检查问题是否可用(在教程状态下)
     * @param pid 问题编号
     * @param user 用户
     * @return 可用返回问题，不可用返回null
     */
    public Problem availableInTutorial(int pid,User user){
        dao.fetchLinks(user,"tutorial");
        dao.fetchLinks(user.getTutorial(),"problems");
        for(Problem problem:user.getTutorial().getProblems()){
            if(problem.getId()==pid) return problem;
        }
        return null;
    }
}
